package com.zishuimuyu.job;


import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.extra.ftp.FtpConfig;
import cn.hutool.extra.ssh.Sftp;
import com.jcraft.jsch.ChannelSftp;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 紫水木鱼
 * @description 测试 Job
 * @company CHAOS
 * @date 2018/10/29 13:48
 */
@Slf4j
public class TestJob {


    public void run() throws Exception {
        Thread t = Thread.currentThread();
        String name = t.getName();
        log.info(DateUtil.now() + name);

    }

    /**
     * sftp上传
     *
     * @param config
     * @param
     * @return java.util.List<java.lang.String>
     */
    public static List<String> sftpUpload(FtpConfig config) {
        List<File> files = FileUtil.loopFiles("E:\\back\\WPFSData");
        boolean uploadResult = false;
        List<String> fileNameList = new ArrayList<>();
        Sftp sftp = new Sftp("47.244.61.206", 22, "root", "alyALY123");
        for (File file : files) {
            ChannelSftp client = sftp.getClient();

            uploadResult = sftp.upload("/root/MLNSOFT", file);
        }
        // sftp.recursiveDownloadFolder(, FileUtil.file("d:/test/download"));
        IoUtil.close(sftp);
        return fileNameList;
    }
}